use codegraph_core::{GraphSystem, Parser};
use codegraph_parser::TreeSitterParser;
use std::path::Path;

#[tokio::test]
async fn test_basic_system_creation() {
    let system = GraphSystem::new().await;
    assert!(system.is_ok());
}

#[tokio::test]
async fn test_parser_creation() {
    let python_parser = TreeSitterParser::python();
    assert!(python_parser.is_ok());
    
    let js_parser = TreeSitterParser::javascript();
    assert!(js_parser.is_ok());
    
    let rust_parser = TreeSitterParser::rust();
    assert!(rust_parser.is_ok());
}

#[tokio::test]
async fn test_basic_parsing() {
    let parser = TreeSitterParser::python().expect("Failed to create Python parser");
    
    let source_code = r#"
def hello_world():
    print("Hello, World!")
    return 42

class MyClass:
    def __init__(self):
        self.value = 10
    
    def get_value(self):
        return self.value
"#;

    let tree = parser.parse(source_code, None).await;
    assert!(tree.is_ok());
    
    let tree = tree.unwrap();
    assert_eq!(tree.language(), "python");
    assert_eq!(tree.source(), source_code);
    
    let root = tree.root_node();
    assert!(root.child_count() > 0);
}

#[tokio::test]
async fn test_project_graph_building() {
    let system = GraphSystem::new().await.expect("Failed to create system");
    
    // Create a temporary directory for testing
    let temp_dir = tempfile::tempdir().expect("Failed to create temp dir");
    let project_path = temp_dir.path();
    
    // Create a simple Python file
    let python_file = project_path.join("test.py");
    std::fs::write(&python_file, r#"
def add(a, b):
    return a + b

def multiply(a, b):
    return a * b

result = add(5, 3)
print(result)
"#).expect("Failed to write test file");
    
    // Try to build the graph
    let graph = system.build_project_graph(project_path, Some("python")).await;
    assert!(graph.is_ok());
    
    let graph = graph.unwrap();
    // For now, the implementation returns empty counts, but the structure should work
    assert_eq!(graph.node_count(), 0); // Will be > 0 when fully implemented
    assert_eq!(graph.edge_count(), 0); // Will be > 0 when fully implemented
}
